using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace ENGINE
{
    class Texture
    {
        public Int16 Width;
        public Int16 Height;
        public Byte[] ColorBuf;
        public Texture()
        { Width = 0; Height = 0; ColorBuf=new byte[0]; }
        public Texture(string FileName, Int16 Width, Int16 Height)
        {
            LoadFromFile(FileName, true, Width, Height);
        }
        public Texture(string FileName)
        {
            LoadFromFile(FileName, false, 0, 0);
        }
        private void LoadFromFile(string FileName, bool ChangeSize, Int16 Width, Int16 Height)
        {
            Bitmap bitmap = new Bitmap(FileName);            
            if (ChangeSize)
            {
                this.Width = Width;
                this.Height = Height;                
            }
            else
            {
                this.Width = (Int16)(bitmap.Width);
                this.Height = (Int16)(bitmap.Height);
            }
            ColorBuf = new Byte[this.Width * this.Height * 3];
            for (int i = 0; i < this.Width; i++)
                for (int j = 0; j < this.Height; j++)
                {
                    Color c = bitmap.GetPixel(bitmap.Width - 1 - i * bitmap.Width / this.Width, 
                                            bitmap.Height - 1 - j * bitmap.Height / this.Height);
                ColorBuf[(j * this.Width + i)*3    ] = c.R;
                ColorBuf[(j * this.Width + i)*3 + 1] = c.G;
                ColorBuf[(j * this.Width + i)*3 + 2] = c.B;
                }
            bitmap.Dispose();            
        }
    }
}
